﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KKU.RBSFPP.Shared.DAC;
using KKU.RBSFPP.Shared.Engines;

namespace KKU.RBSFPP.Web.Administrator.Controllers
{
    [Authorize(Users = "admin")]
    public class ProductPricingPerUnitController : Controller
    {
        private RBSFPPModelContainer db = new RBSFPPModelContainer();

        //
        // GET: /ProductPricingPerUnit/

        public ActionResult Index()
        {
            return View(db.ProductPricingPerUnits.ToList().Display());
        }

        //
        // GET: /ProductPricingPerUnit/Details/5

        public ActionResult Details(int id = 0)
        {
            ProductPricingPerUnit productpricingperunit = db.ProductPricingPerUnits.Single(p => p.Id == id);
            if (productpricingperunit == null)
            {
                return HttpNotFound();
            }
            return View(productpricingperunit);
        }

        //
        // GET: /ProductPricingPerUnit/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /ProductPricingPerUnit/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(ProductPricingPerUnit productpricingperunit)
        {
            if (ModelState.IsValid)
            {
                productpricingperunit.Create();
                db.ProductPricingPerUnits.AddObject(productpricingperunit);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(productpricingperunit);
        }

        //
        // GET: /ProductPricingPerUnit/Edit/5

        public ActionResult Edit(int id = 0)
        {
            ProductPricingPerUnit productpricingperunit = db.ProductPricingPerUnits.Single(p => p.Id == id);
            if (productpricingperunit == null)
            {
                return HttpNotFound();
            }
            return View(productpricingperunit);
        }

        //
        // POST: /ProductPricingPerUnit/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(ProductPricingPerUnit productpricingperunit)
        {
            if (ModelState.IsValid)
            {
                db.ProductPricingPerUnits.Attach(productpricingperunit);
                db.ObjectStateManager.ChangeObjectState(productpricingperunit, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(productpricingperunit);
        }

        //
        // GET: /ProductPricingPerUnit/Delete/5

        public ActionResult Delete(int id = 0)
        {
            ProductPricingPerUnit productpricingperunit = db.ProductPricingPerUnits.Single(p => p.Id == id);
            if (productpricingperunit == null)
            {
                return HttpNotFound();
            }
            return View(productpricingperunit);
        }

        //
        // POST: /ProductPricingPerUnit/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            ProductPricingPerUnit productpricingperunit = db.ProductPricingPerUnits.Single(p => p.Id == id);
            //db.ProductPricingPerUnits.DeleteObject(productpricingperunit);
            productpricingperunit.Delete();
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}